
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!doctype html>
<html>
<head>
    <title>Title</title>
    <jsp:include page="/_layout/_css.jsp"/>
    <link rel="stylesheet" href="${ctx}/resources/css/plugins/bootstrap-table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${ctx}/resources/css/plugins/datapicker/datepicker3.css"/>
    <link rel="stylesheet" href="${ctx}/resources/js/plugins/datapicker/bootstrap-datepicker.js"/>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <row>
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>基本</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>

                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="btn btn-primary" onclick="addUser()">添加工资信息</div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </row>
</div>
</body>
<div class="col-sm-12" id="pop" style="display:none">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form class="form-horizontal m-t" id="commentForm" novalidate="novalidate">
                <div class="form-group">
                    <label class="col-sm-3 control-label">出勤天数：</label>
                    <div class="col-sm-8">
                        <input type="text" name="days" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">出勤奖：</label>
                    <div class="col-sm-8">
                        <input type="text" name="attendanceBonus" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">加班工时：</label>
                    <div class="col-sm-8">
                        <input id="curl" type="text" class="form-control" name="workingHours">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">加班工资：</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" name="overtimeePay">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">绩点：</label>
                    <div class="col-sm-8">
                        <input type="text" name="achievementPoint" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">绩效奖：</label>
                    <div class="col-sm-8">
                        <input type="text" name="meritPay" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">底工资：</label>
                    <div class="col-sm-8">
                        <input type="text" name="basePay" class="form-control" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">应发工资：</label>
                    <div class="col-sm-8">
                        <input type="text" name="wagesPayable" class="form-control" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">实发工资：</label>
                    <div class="col-sm-8">
                        <input type="text" name="realWages" class="form-control" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">月份：</label>
                    <div class="col-sm-8">
                        <select name="month" class="form-control">

                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">员工id：</label>
                    <div class="col-sm-8">
                        <select name="eid" class="form-control">

                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3">
                        <div class="btn btn-primary"  onclick="save()">提交</div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="ibox float-e-margins" id="ppp" style="display: none">
    <div class="ibox-content">
        <form class="form-horizontal m-t" id="commentForm1" novalidate="novalidate">
            <div class="form-group">
                <label class="col-sm-3 control-label">id：</label>
                <div class="col-sm-8">
                    <input type="text" id="id" name="id" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">出勤天数：</label>
                <div class="col-sm-8">
                    <input type="text" id="days" name="days" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">出勤奖：</label>
                <div class="col-sm-8">
                    <input type="text" id="attendanceBonus" name="attendanceBonus" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">加班工时：</label>
                <div class="col-sm-8">
                    <input id="workingHours" type="text" class="form-control" name="workingHours">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">加班工资：</label>
                <div class="col-sm-8">
                    <input type="text" id="overtimeePay" class="form-control" name="overtimeePay">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">绩点：</label>
                <div class="col-sm-8">
                    <input type="text" id="achievementPoint" name="achievementPoint" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">绩效奖：</label>
                <div class="col-sm-8">
                    <input type="text" id="meritPay" name="meritPay" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">底工资：</label>
                <div class="col-sm-8">
                    <input type="text" id="basePay" name="basePay" class="form-control" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">应发工资：</label>
                <div class="col-sm-8">
                    <input type="text" id="wagesPayable" name="wagesPayable" class="form-control" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">实发工资：</label>
                <div class="col-sm-8">
                    <input type="text" id="realWages" name="realWages" class="form-control" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">月份：</label>
                <div class="col-sm-8">

                    <select id="month" name="month" class="form-control">

                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">员工id：</label>
                <div class="col-sm-8">
                    <select id="eid" name="eid" class="form-control">

                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-3">
                    <div class="btn btn-primary"  onclick="save2()">提交</div>
                </div>
            </div>
        </form>
    </div>
</div>
<jsp:include page="/_layout/_script.jsp"/>
<script src="${ctx}/resources/js/plugins/bootstrap-table/bootstrap-table.min.js"/>
<script src="${ctx}/resources/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script>
    $.get('${ctx}/wages/list',function (r) {
        $('#table').bootstrapTable({
            url: '${ctx}/wages/list',
            columns: [{
                field: 'id',
                title: '工资编号'
            },{
                field: 'days',
                title: '出勤天数'
            }, {
                field: 'attendanceBonus',
                title: '出勤奖'
            }, {
                field: 'workingHours',
                title: '加班工时'
            }, {
                field: 'overtimeePay',
                title: '加班工资'
            }, {
                field: 'achievementPoint',
                title: '绩点'
            }, {
                field: 'meritPay',
                title: '绩效奖'
            }, {
                field: 'basePay',
                title: '底工资'
            }, {
                field: 'wagesPayable',
                title: '应发工资'
            },{
                field: 'realWages',
                title: '实发工资'
            },{
                field: 'month',
                title: '工资月份'
            },{
                field: 'eid',
                title: '员工id'
            },{
                title: '操作',
                formatter:function (v1,v2) {
                    id=v2['id'];
                    return "<div class='btn btn-xs btn-danger' onclick='removeThis("+id+")'>删除</div> " +
                        "<div  class='btn btn-xs btn-warning' onclick='update("+id+")'>修改</div>"
                }
            }],
            pagination:true,
            pageSize:6,
            pageList:[2,3,6],
            search:false,
            showColumns:true,
            showColumns:true,
            sidePagination:"server",
            queryParamsType:''
        });
    },'json')

    function removeThis(id){
        if (confirm("确定删除当前数据？")) {
            $.get('${ctx}/wages/remove/'+id,function (r) {
                if(r['code']==200){
                    layer.msg("删除成功");

                    $('#table').bootstrapTable('refresh');
                }
            },'json');
        }
    }


    //显示添加员工页面
    function addUser() {
        layer.open({
            title:'添加用户',
            type:1,
            content:$('#pop'),
            area:'50%'
        });
    }
    //显示修改页面
    /* function update(id) {
         layer.open({
             title:'修改用户',
             type:1,
             content:$('#ppp'),
             area:'50%'
         });
         $('#id').attr("value",id)
     }*/

    function save2(){

        $.post('${ctx}/wages/update',$('#commentForm1').serialize(),function (r) {
            if(r['code']==200){
                parent.layer.msg('操作成功');
                $('#table').bootstrapTable('refresh');
                layer.closeAll();
            }else{
                layer.msg('操作失败');
            }
        },'json')
    }

    /**
     *查询部门和角色表
     */

    //通过id查询
    function update(id){
        layer.open({
            title:'修改工资信息',
            type:1,
            content:$('#ppp'),
            area:'50%'
        });
        $.get('${ctx}/wages/id/'+id,function (r) {
            wages = r['wages'];
            console.log(wages);
            $('#id').attr("value",wages.id);
            $('#days').attr("value",wages['days']);
            $('#attendanceBonus').attr("value",wages['attendanceBonus']);
            $('#workingHours').attr("value",wages['workingHours']);
            $('#overtimeePay').attr("value",wages['overtimeePay']);
            $('#achievementPoint').attr("value",wages['achievementPoint']);
            $('#meritPay').attr("value",wages['meritPay']);
            $('#basePay').attr("value",wages['basePay']);
            $('#wagesPayable').attr("value",wages['wagesPayable']);
            $('#realWages').attr("value",wages['realWages']);
            $('#month').attr("value",wages['month']);
            $('#eid').attr("value",wages['eid']);


        },'json')
    }



    //角色
    $.get('${ctx}/employee/list',function (r) {
        ename = r['rows'];
        console.log(ename);
        str='';
        for(y=0;y<ename.length;y++){
            str+='<option value="'+ename[y]['id']+'">'+ename[y]['id']+'</option>'
        };
        $('[name=eid]').html(str);
    },'json')

    $('[name=month]',function () {
        var mm = new Date().getMonth()+1;
        stt='';
        console.log();
        for (i=0;i<12;i++){
            stt+='<option value="'+(mm+i)+'月">'+(mm+i)+'月</option>'
        };
        $('[name=month]').html(stt);
    })




    function save(){
        $.get('${ctx}/wages/add',$('form').serialize(),function (r) {
            if(r['code']==200){
                parent.layer.msg('操作成功');
                $('#table').bootstrapTable('refresh');
                layer.closeAll();
            }else{
                layer.msg('操作失败');
            }
        },'json')
    }



</script>
</html>
